<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div>
      <button class="btn">弹出框</button>
      <div class="overlay"></div>
      <div class="box">
        <h2><span class="qu">×</span></h2>
      </div>
    </div>
  </body>
  <script>
    let btn = document.querySelector(".btn");
    let box = document.querySelector(".box");
    let qu = document.querySelector(".qu");
    let overlay = document.querySelector(".overlay");
    btn.onclick = function () {
      box.style.display = "block";
      overlay.style.display = "block";
    };
    qu.onclick = function () {
      box.style.display = "none";
      overlay.style.display = "none";
    };
  </script>
  <style>
    * {
      margin: 0;
      padding: 0;
    }
    body {
      position: relative;
      text-align: center;
    }
    .box {
      position: absolute;
      top: 50%;
      left: 50%;
      margin-top: -150px;
      margin-left: -200px;
      width: 400px;
      height: 300px;
      background: skyblue;
      display: none;
    }
    h2 {
      width: 100%;
      height: 44px;
      background: orange;
    }
    .qu {
      float: right;
      margin-right: 10px;
    }
    .overlay {
      position: absolute;
      top: 0;
      left: 0;
      width: 100%;
      height: 100%;
      background: #000;
      opacity: 0.5;
      /* filter: alpha(
        opacity=50
      );  */
      display: none;
    }
  </style>
</html>
